<?php


function excel_khk_kalkulasi($periode_id){
	$header = array(
		'NIK'=>array(),  
		'Nama'=>array(),   
		'Jam'=>array(),  
	//	'Tunjangan'=>array(), 
	);
	
	$query = " SELECT  a.karyawan_id ,b.nik, a.nhari FROM tmn_khk a
				INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id  
				WHERE a.periode_id = {$periode_id}
				";
	$result = my_query($query);
	while($ey = my_fetch_array($result )){ 
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$row[] = array( 
			'nik'=>  "'".sprintf('%07d',$ey['nik']),    
			'nama'=>ucfirst($karyawan['nama']),
			'baru'=>  $ey['nhari'], 
	//		'lama'=>  $ey['nominal'] , 
		);
	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas ,4 ,false ); 	
}

 
function list_karyawan_khk($periode_id){
	$periode_gaji_id = get_periode_gaji() ;
	if($periode_id==0){
		$periode_id=$periode_gaji_id ;
	}
	my_set_code_js('
		function confirmRst(){
			var t = confirm(\'Yakin akan reset data ?\');
			if(t){
				location.href=\'index.php?com='.$_GET['com'].'&task=rst\';
			}
			return false;
		}
	');
	$header = array(
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama'=>array('style'=>'text-align:left;border-bottom:2px solid;width:35%'),  
		'Jabatan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:30%'),  
		'khk'=>array('style'=>'text-align:center;border-bottom:2px solid;width: 5%'),  
	//	'Tunjangan'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'), 
	);
	if(isset($_GET['key']))
	$query = "SELECT   a.karyawan_id , a.nhari   FROM  tmn_khk a
				INNER JOIN   karyawan c  ON a.karyawan_id = c.karyawan_id
		INNER JOIN biodata d ON d.biodata_id = c.biodata_id
		WHERE c.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable) 
		AND ( c.nik='{$_GET['key']}' OR d.nama LIKE '%{$_GET['key']}%' )	
		AND periode_id = {$periode_id}
		 ORDER BY c.nik ASC
		";
	else
	$query = " SELECT  a.karyawan_id , a.nhari FROM  tmn_khk a
				INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id  
				AND a.periode_id = {$periode_id}
				";
	
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =7;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		  
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&periode_id={$_GET['periode_id']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	
	$kgPagerOBJ = new kgPager();
			$kgPagerOBJ->pager_set(
				$pager_url, 
				$total_records, 
				$scroll_page, 
				$per_page, 
				$current_page, 
				$inactive_page_tag, 
				$previous_page_text, 
				$next_page_text, 
				$first_page_text, 
				$last_page_text ,$pager_url_last); 
				
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result)){
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		if(empty($karyawan['gelar'])){
			$nama_karyawan=ucfirst($karyawan['nama']) ;
		}else{
			$nama_karyawan=trim(ucfirst($karyawan['nama'])).", ".$karyawan['gelar'] ;
		}

		$jabatan = my_get_data_by_id('jabatan' ,'jabatan_id' , ($karyawan['jabatan_id']<>'' ? $karyawan['jabatan_id'] : 0 ));
		
		$editproperty = array(
						'href'=>'index.php?com=pr_upload_gaji&task=edit&komponen_gaji_id='.$komponen_gaji_id.'&id='.$ey['gaji_upload_view_id'],
						'rel'=>'facebox',
						'title'=>'Edit'
				);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );
		 
		$deleteproperty = array(
						'href'=>'javascript:; ',
						'onclick'=>'javascript:confirmDelete('.$ey['tmn_khk_id'].');',
						'title'=>'Delete'
				);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		$row[] = array(
			'nik'=>position_text_align ($karyawan['nik'] ,'center'),    
			'gd'=> $nama_karyawan ,      
			'jabatan'=> $jabatan['nama_jabatan']   ,
			'khk'=> position_text_align( $ey['nhari'] , 'center'),
		//	'tunj'=> position_text_align( rp_format($ey['nominal']) , 'right'),
		); 
	}
	$datas = table_rows($row);
	$paging = $kgPagerOBJ ->showPaging();	
//	$periode_gajis = my_get_data_by_id('pr_periode','periode_id',$periode_id); 	 
	 
	 $view = form_header( "..." , "..."  );
	$query_check_periode = " SELECT * FROM pr_periode where periode_id <= {$periode_gaji_id} ORDER BY periode_id DESC";
	$result = my_query($query_check_periode);
	$prs = array();
	while($prow = my_fetch_array($result)){
		$prs[$prow['periode_id']] = date('m-Y',strtotime($prow['tanggal']));
	}
	$fperiode_id = array(
		'id'=>'periode_id',
		'value'=>$periode_id ,
		'name'=>'periode_id',
	);
	$view .= '<input type="hidden"  value="'.$_GET['com'].'" name="com" />';
	$view .= form_field_display( form_dropdown($fperiode_id,$prs)   , "Periode Gaji"   );	 
	$form_start = '<input type="text" size="7" value="'.$nik_start.'" name="nik_start" />';
	$form_end = '<input type="text" size="7" value="'.$nik_end.'" name="nik_end" />';
	$view .= form_field_display( $form_start.' s/d '.$form_end  , "NIK Range"   );
	$submit = array(
		'value' => (  ' Check '  ),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 	
	$cetak = array(
		'value' => (  ' Cetak '  ),
		'onclick'=>'javascript:window.open(\'index.php?com='.$_GET['com'].'&task=txt_list_of_transfer&periode_id='.$periode_id.'&nik_start='.$nik_start.'&nik_end='.$nik_end.'\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,scrollbars,resizable=1\');',
		'type'=>'button','class'=>'main_button'
	);
	$form_cetak= form_dynamic($cetak); 	
 
	$excel = array(
		'value' => (  ' Excel '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&task=excel_report_khk&periode_id='.$periode_id.'&nik_start='.$nik_start.'&nik_end='.$nik_end.'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_excel= form_dynamic($excel); 
	$view .= form_field_display( $form_submit .'  '.$form_excel , "&nbsp;" ,  "" );
	$view .= form_footer( );
	$view = str_replace("method=\"post\"","method=\"get\"",$view);
			return  $view.   table_builder($header , $datas ,  6 , false ,$paging );	

}
